package com.woniuxy.education.mapper;

import com.woniuxy.education.entity.Article;
import com.woniuxy.education.entity.PageResult;
import com.woniuxy.education.entity.SelectArticle;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author author
 * @create 2021/4/2
 *
 * 文章操作映射文件
 */

@Mapper
public interface ArticleMapper {

    //查询所有文章
//    @Select("select * from article")
//    List<Article> findAllArticle();

    //通过id查询文章
    @Select("select * from article where id =#{id}")
    Article findById (int id);

    //通过文章状态查询文章
    @Select("select * from article where state = #{state}")
    List<Article> findArticleByState(int state);

    //动态sql条件查询 状态  类型  名称
    @Select("<script> select * from article " +
            "<where> " +
            "<if test =\"state!=null\">" +
            "and state = #{state} " +
            "</if>"+
            "<if test =\"type!=null\">" +
            "and type = #{type} " +
            "</if>"+
            "<if test =\"article_name != null and article_name != ''\">" +
            "and article_name like #{article_name}" +
            "</if>"+
            "</where>"+
            "</script>")
    List<Article> findAllArticle(SelectArticle selectArticle);

    //分页查询
    @Select("select * from article limit #{index},#{size}")
    List<Article>findByPage(@Param("index") int index,@Param("size") int size);

    //上传文章
    @Insert("insert into article values(default,#{article_name},#{writer},#{upload_time},#{type},#{content},#{view_num},#{collection_num},#{state})")
    boolean addArticle(Article article);

    //修改文章1状态（0-审核中   1-已通过  2-未审核  3-未通过）
    @Update("update article set state = 1 where id = #{id}")
    boolean updateOneState(@Param("id") int id);
    //修改文章2状态（0-审核中   1-已通过  2-未审核  3-未通过）
    @Update("update article set state = 2 where id = #{id}")
    boolean updateTwoState(@Param("id") int id);
    //修改文章3状态（0-审核中   1-已通过  2-未审核  3-未通过）
    @Update("update article set state = 3 where id = #{id}")
    boolean updateThreeState(@Param("id") int id);



}
